
<template>
  <div>
    <el-row :gutter="20">
      <el-col :span="8">
        <el-card shadow="hover" class="mgb20" style="height:252px;">
          <div class="user-info">
            <img src="../../assets/img/img.jpg" class="user-acator">
            <div class="user-info-cont">
              <div class="user-info-name">{{name}}</div>
              <div>{{role}}</div>
            </div>
          </div>
          <div class="user-info-list">
            上次登录时间：
            <span>2019-1-1</span>
          </div>
          <div class="user-info-list">
            上次登录地点：
            <span>长沙</span>
          </div>
        </el-card>
        <el-card shadow="hover" style="height:252px">
          <div slot="header" class="clearfix">
            <span>语言详情</span>
          </div>Vue
          <el-progress :percentage="71.3" color="#FF5500"></el-progress>Java Script
          <el-progress :percentage="25.6"></el-progress>Scala
          <el-progress :percentage="54.1"></el-progress>Android
          <el-progress :percentage="15.3"></el-progress>
        </el-card>
      </el-col>
      <el-col :span="16">
        <el-row :gutter="20" class="mgb20">
          <el-col :span="8">
            <el-card shadow="hover" :body-style="{padding:'0px'}">
              <div class="grid-content grid-con-1">
                <i class="el-icon-lx-people grid-con-icon"></i>
                <div class="grid-cont-right">
                  <div class="grid-num">1232</div>
                  <div>用户访问量</div>
                </div>
              </div>
            </el-card>
          </el-col>
          <el-col :span="8">
            <el-card shadow="hover" :body-style="{padding:'0px'}">
              <div class="grid-content grid-con-2">
                <i class="el-icon-lx-notice grid-con-icon"></i>
                <div class="grid-cont-right">
                  <div class="grid-num">213</div>
                  <div>系统消息</div>
                </div>
              </div>
            </el-card>
          </el-col>
          <el-col :span="8">
            <el-card shadow="hover" :body-style="{padding:'0px'}">
              <div class="grid-content grid-con-2">
                <i class="el-icon-lx-notice grid-con-icon"></i>
                <div class="grid-cont-right">
                  <div class="grid-num">6000</div>
                  <div>数量</div>
                </div>
              </div>
            </el-card>
          </el-col>
        </el-row>
        <el-card shadow="hover" style="height:403px">
          <div slot="header" class="clearfix">
            <el-tabs v-model="activeName2" type="card" @tab-click="handleClick">
              <el-tab-pane label="用户留言" name="first">
                <el-table
                  :data="todoList"
                  :show-header="false"
                  height="304"
                  style="width:100%;font-siz:14px;"
                >
                  <el-table-column>
                    <template slot-scope="scope">
                      <h3>{{scope.row.title}}</h3>
                      <p>{{scope.row.content}}</p>
                      <span>{{scope.row.date}}</span>
                    </template>
                  </el-table-column>
                </el-table>
              </el-tab-pane>
              <el-tab-pane label="待办事项" name="second">
                <el-table
                  :data="todoList1"
                  :show-header="false"
                  height="304"
                  style="width: 100%;font-size:14px;"
                >
                  <el-table-column width="40">
                    <template slot-scope="scope">
                      <el-checkbox v-model="scope.row.status"></el-checkbox>
                    </template>
                  </el-table-column>
                  <el-table-column>
                    <template slot-scope="scope">
                      <div
                        class="todo-item"
                        :class="{'todo-item-del': scope.row.status}"
                      >{{scope.row.title}}</div>
                    </template>
                  </el-table-column>
                  <el-table-column width="60">
                    <template slot-scope>
                      <i class="el-icon-edit"></i>
                      <i class="el-icon-delete"></i>
                    </template>
                  </el-table-column>
                </el-table>
              </el-tab-pane>
            </el-tabs>
          </div>
        </el-card>
      </el-col>
    </el-row>
    <el-row :gutter="20">
      <el-col :span="12">
        <el-card shadow="hover">
          <div style="height:300px;" class="echart-box" id="E_zkcl"></div>
        </el-card>
      </el-col>
      <el-col :span="12">
        <el-card shadow="hover">
          <schart
            ref="line"
            class="schart"
            canvasId="line"
            :data="data"
            type="line"
            :options="options2"
          ></schart>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>


<script>
import Schart from "vue-schart";
import bus from "../pages/bus";

export default {
  name: "dashboard",
  data() {
    return {
      name: localStorage.getItem("ms_username"),
      activeName2: "first",
      todoList1: [
        {
          title: "今天要修复100个bug",
          status: false
        },
        {
          title: "今天要修复100个bug",
          status: false
        },
        {
          title: "今天要写100行代码加几个bug吧",
          status: false
        },
        {
          title: "今天要修复100个bug",
          status: false
        },
        {
          title: "今天要修复100个bug",
          status: true
        },
        {
          title: "今天要写100行代码加几个bug吧",
          status: true
        }
      ],
      todoList: [
        {
          title: "诸葛亮",
          content:
            "皓首匹夫！苍髯老贼！你枉活九十有六，一生未立寸功，只会摇唇鼓舌！助曹为虐！一条断脊之犬，还敢在我军阵前狺狺狂吠，我从未见过有如此厚颜无耻之人！",
          date: "5月02日"
        },
        {
          title: "暗裔剑魔",
          content: "心怀恐惧的死去，或者手染鲜血的获胜。",
          date: "5月11日"
        },
        {
          title: "杜甫",
          content: "人才虽高，不务学问，不能致圣。刘向十日画一水，五日画一石。",
          date: "4月11日"
        },
        {
          title: "鲁迅",
          content: "路本是无所谓有和无的，走的人多了，就没路了。。",
          date: "4月28日"
        },
        { title: "艾克", content: "某人的日子就要难过啦。", date: "2月28日" },
        {
          title: "泰坦",
          content: "倘若你迷失在黑暗之中,除了前行别无他法。",
          date: "4月21日"
        },
        {
          title: "艾克",
          content: "我宁愿犯错误，也不愿什么都不做。",
          date: "3月2日"
        }
      ],
      data: [
        {
          name: "2018/09/04",
          value: 1083
        },
        {
          name: "2018/09/05",
          value: 941
        },
        {
          name: "2018/09/06",
          value: 1139
        },
        {
          name: "2018/09/07",
          value: 816
        },
        {
          name: "2018/09/08",
          value: 327
        },
        {
          name: "2018/09/09",
          value: 228
        },
        {
          name: "2018/09/10",
          value: 1065
        }
      ],
      options: {
        title: "最近七天每天的用户访问量",
        showValue: false,
        fillColor: "rgb(45, 140, 240)",
        bottomPadding: 30,
        topPadding: 30
      },
      options2: {
        title: "最近七天用户访问趋势",
        fillColor: "#FC6FA1",
        axisColor: "#008ACD",
        contentColor: "#EEEEEE",
        bgColor: "#F5F8FD",
        bottomPadding: 30,
        topPadding: 30
      }
    };
  },
  components: {
    Schart
  },
  computed: {
    role() {
      return this.name === "admin" ? "超级管理员" : "普通用户";
    }
  },
  created() {
    this.handleListener();
    this.changeDate();
  },
  activated() {
    this.handleListener();
  },
  deactivated() {
    window.removeEventListener("resize", this.renderChart);
    bus.$off("collapse", this.handleBus);
  },
  methods: {
    drawLine() {
      let myChart1 = this.$echarts.init(document.getElementById("E_zkcl"));
      myChart1.setOption({
        color: ["#4ED8DA"],
        title: {
          text: "每月检修统计",
          x: 15,
          y: 15,
          textStyle: {
            fontSize: 16,
            fontWeight: "bolder",
            color: "#333"
          }
        },
        tooltip: {
          trigger: "axis"
        },
        grid: {
          borderWidth: 0,
          x: "10%",
          y: "20%",
          x2: "5%",
          y2: "15%"
        },
        calculable: true,
        xAxis: [
          {
            type: "category",
            axisLine: {
              show: false
            },
            splitLine: {
              show: false //不显示分割线
            },
            data: []
          }
        ],
        yAxis: [
          {
            type: "value",
            axisLine: {
              show: false
            }
          }
        ],
        series: [
          {
            name: "数量",
            type: "bar",
            data: []
          }
        ]
      });
      var params = new URLSearchParams();
      this.postRequest("/data", {
        }).then(successResponse => {
        this.responseResult = JSON.stringify(successResponse.data);
        console.log("data ===>" + successResponse.data.data);
        console.log("num ===>" + successResponse.data.num);
        var datas = new Array();
        var num = new Array();
        console.log("data 数量-->" + datas.length);
        for (var i = 0; i < successResponse.data.length; i++) {
          datas.push(successResponse.data[i].data);
          num.push(successResponse.data[i].num);
        }
        console.log("data 数量-->" + datas.length);
      });
    },
    changeDate() {
      const now = new Date().getTime();
      this.data.forEach((item, index) => {
        const date = new Date(now - (6 - index) * 86400000);
        item.name = `${date.getFullYear()}/${date.getMonth() +
          1}/${date.getDate()}`;
      });
    },
    handleListener() {
      bus.$on("collapse", this.handleBus);
      // 调用renderChart方法对图表进行重新渲染
      window.addEventListener("resize", this.renderChart);
    },
    handleBus(msg) {
      setTimeout(() => {
        this.renderChart();
      }, 300);
    },
    renderChart() {
      // this.$refs.bar.renderChart();
      this.$refs.line.renderChart();
    }
  },
  mounted() {
    this.drawLine();
  }
};
</script>



<style scoped>
.el-row {
  margin-bottom: 20px;
}

.grid-content {
  display: flex;
  align-items: center;
  height: 100px;
}

.grid-cont-right {
  flex: 1;
  text-align: center;
  font-size: 14px;
  color: #999;
}

.grid-num {
  font-size: 30px;
  font-weight: bold;
}

.grid-con-icon {
  font-size: 50px;
  width: 100px;
  height: 100px;
  text-align: center;
  line-height: 100px;
  color: #fff;
}

.grid-con-1 .grid-con-icon {
  background: rgb(45, 140, 240);
}

.grid-con-1 .grid-num {
  color: rgb(45, 140, 240);
}

.grid-con-2 .grid-con-icon {
  background: rgb(100, 213, 114);
}

.grid-con-2 .grid-num {
  color: rgb(45, 140, 240);
}

.grid-con-3 .grid-con-icon {
  background: rgb(242, 94, 67);
}

.grid-con-3 .grid-num {
  color: rgb(242, 94, 67);
}

.user-info {
  display: flex;
  align-items: center;
  padding-bottom: 20px;
  border-bottom: 2px solid #ccc;
  margin-bottom: 20px;
}

.user-avator {
  width: 120px;
  height: 120px;
  border-radius: 50%;
}

.user-info-cont {
  padding-left: 50px;
  flex: 1;
  font-size: 14px;
  color: #999;
}

.user-info-cont div:first-child {
  font-size: 30px;
  color: #222;
}

.user-info-list {
  font-size: 14px;
  color: #999;
  line-height: 25px;
}

.user-info-list span {
  margin-left: 70px;
}

.mgb20 {
  margin-bottom: 20px;
}

.todo-item {
  font-size: 14px;
}

.todo-item-del {
  text-decoration: line-through;
  color: #999;
}

.schart {
  width: 100%;
  height: 300px;
}
</style>
